﻿using System;
using System.Threading.Tasks;
using Windows.UI.Popups;
using com.IronOne.BoardPACWinAppUtil.Enums;

namespace com.IronOne.BoardPACWinApp.Helpers
{
    public class DialogService : IDialogService
    {
        public async Task ShowMessage(string message)
        {
            var mDialog = new MessageDialog(message);
            await mDialog.ShowAsync();
        }

        /// <summary>
        /// </summary>
        /// <param name="message"></param>
        /// <param name="defCommand"></param>
        /// <returns></returns>
        public async Task<bool> ShowMessageYesNo(string message, DefaultButtonCommand defCommand)
        {
            var messageDialog = new MessageDialog(message);
            var result = false;
            // Add commands and set their callbacks
            messageDialog.Commands.Add(new UICommand("Yes", command => { result = true; }));
            messageDialog.Commands.Add(new UICommand("No", command => { result = false; }));
            // Set the command that will be invoked by default
            messageDialog.DefaultCommandIndex = (uint) defCommand;
            // Show the message dialog
            await messageDialog.ShowAsync();
            return result;
        }

        /// <summary>
        /// </summary>
        /// <param name="message"></param>
        /// <param name="defCommand"></param>
        /// <returns></returns>
        public async Task<bool> ShowMessageRestartCancel(string message, DefaultButtonCommand defCommand)
        {
            var messageDialog = new MessageDialog(message);
            var result = false;
            // Add commands and set their callbacks
            messageDialog.Commands.Add(new UICommand("Restart", command => { result = true; }));
            messageDialog.Commands.Add(new UICommand("Cancel", command => { result = false; }));
            // Set the command that will be invoked by default
            messageDialog.DefaultCommandIndex = (uint) defCommand;
            // Show the message dialog
            await messageDialog.ShowAsync();
            return result;
        }

        /// <summary>
        /// </summary>
        /// <param name="message"></param>
        /// <param name="defCommand"></param>
        /// <param name="yesText"></param>
        /// <param name="noText"></param>
        /// <param name="cancelText"></param>
        /// <returns></returns>
        public async Task<bool?> ShowMessageYesNoCancel(string message, DefaultButtonCommand defCommand,
            string yesText = "Yes", string noText = "No", string cancelText = "Cancel")
        {
            var messageDialog = new MessageDialog(message);
            bool? result = false;
            // Add commands and set their callbacks
            messageDialog.Commands.Add(new UICommand(yesText, command => { result = true; }));
            messageDialog.Commands.Add(new UICommand(noText, command => { result = false; }));
            messageDialog.Commands.Add(new UICommand(cancelText, command => { result = null; }));

            // Set the command that will be invoked by default
            messageDialog.DefaultCommandIndex = (uint) defCommand;
            await messageDialog.ShowAsync();
            return result;
        }
    }
}